package com.zuoyy.modules.system.service.impl;

import com.zuoyy.common.enums.StatusEnum;
import com.zuoyy.modules.common.BaseServiceImpl;
import com.zuoyy.modules.system.domain.Post;
import com.zuoyy.modules.system.query.PostQuery;
import com.zuoyy.modules.system.repository.PostRepository;
import com.zuoyy.modules.system.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 
 */
@Service
public class PostServiceImpl extends BaseServiceImpl<Post> implements PostService {

    @Autowired
    private PostRepository postRepository;



    @Override
    public Page<Post> getPageList(PostQuery query) {
        // 创建分页对象
        Pageable pageable = PageRequest.of(query.getPageIndex(), query.getPageSize(), new Sort(query.getSort(),query.getColumn()));
        return postRepository.findAll(query,pageable);
    }

    @Override
    public List<Post> findByQuery(PostQuery query) {
        return postRepository.findAll(query);
    }

    @Override
    public List<Post> findByQuery(PostQuery query, Sort sort) {
        return postRepository.findAll(query,sort);
    }

    @Override
    @Transactional
    public Boolean updateStatus(StatusEnum statusEnum, List<String> idList) {
        return postRepository.updateStatus(statusEnum.code,idList) > 0;
    }


}